package com.company.eduservice.controller;


import com.company.eduservice.entity.EduVideo;
import com.company.eduservice.feign.VideoFeignService;
import com.company.eduservice.service.EduVideoService;
import com.company.utils.R;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-04-18
 */
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {

    @Resource
    private EduVideoService eduVideoService;

    @Resource
    private VideoFeignService videoFeignService;

    //添加章节下的小节
    @PostMapping("/addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.save(eduVideo);
        return R.ok();
    }

    //删除小节
    @DeleteMapping("/{id}")
    public R deleteVideo(@PathVariable String id) {
        String videoSourceId = eduVideoService.getById(id).getVideoSourceId();
        if (!StringUtils.isEmpty(videoSourceId)) {
            videoFeignService.removeAlyVideo(videoSourceId);
        }
        eduVideoService.removeById(id);
        return R.ok();
    }


}

